package com.snc.controller.app;


import com.snc.controller.index.BaseController;
import com.snc.entity.*;
import com.snc.plugin.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * APP-活动
 */
@Controller
@RequestMapping("/app/styy")
public class StuTeacherYYController extends BaseController {

    /**
     * 获取活动的列表，
     * 请求参数：
     *
     * @return 数据
     */
    @ResponseBody
    @RequestMapping(value = "/list")
    public Result list() {
        StuTeacherYYFormMap map = super.toFormMap(StuTeacherYYFormMap.class);
        return Result.Success(StuTeacherYYFormMap.mapper().select(map));
    }
    /**
     * 获取活动的列表，
     * 请求参数：
     *
     * @return 数据
     */
    @ResponseBody
    @RequestMapping(value = "/tlist")
    public Result tlist() {
        StuTeacherYYFormMap map = super.toFormMap(StuTeacherYYFormMap.class);
        return Result.Success(StuTeacherYYFormMap.mapper().selectt(map));
    }


    /**
     * 查询申请消息的详情，请求参数：id
     * @return
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/info")
    public Result info(){
        StuTeacherYYFormMap map = super.toFormMap(StuTeacherYYFormMap.class);

        map = map.findbyFrist();

        //查询教练信息
        Long teacherId = map.getLong("teacherId");
        map.put("teacher",new ResidentFormMap().findByAttribute("id",teacherId).get(0));
        //查询学生
        Long stuId = map.getLong("stuId");
        map.put("student",new ResidentFormMap().findByAttribute("id",stuId).get(0));
        //查询学校
        Long school = map.getLong("school");
        map.put("school",new SchoolFormMap().findByAttribute("id",school).get(0));

        return Result.Success(map);
    }
    /**
     * 获取活动的列表，
     * 请求参数：
     *
     * @return 数据
     */
    @ResponseBody
    @RequestMapping(value = "/jd")
    public Result jd(Long teacherId) {
        //学员列表
        StuTeacherFormMap map = super.toFormMap(StuTeacherFormMap.class);

        List<StuTeacherFormMap> users = StuTeacherFormMap.mapper().select(map);
        for (StuTeacherFormMap u : users) {
            List<Map> jd = StuTeacherYYFormMap.mapper().select2(super.toFormMap(StuTeacherYYFormMap.class));
            u.put("jd",jd);
        }

        return Result.Success(users);
    }

    @ResponseBody
    @RequestMapping("/add")
    public Result add() throws Exception {
        StuTeacherYYFormMap map = super.toFormMap(StuTeacherYYFormMap.class);
        map.save();
        return Result.Success(null);
    }

    @ResponseBody
    @RequestMapping("/update")
    public Result update() throws Exception {
        StuTeacherYYFormMap map = super.toFormMap(StuTeacherYYFormMap.class);
        map.update();
        return Result.Success(null);
    }


    @ResponseBody
    @RequestMapping("/del")
    public Result del() throws Exception {
        StuTeacherYYFormMap map = super.toFormMap(StuTeacherYYFormMap.class);
        return Result.Success(null);
    }

}